<%--
  Created by IntelliJ IDEA.
  tip: lichengming
  Date: 2017/6/14
  Time: 下午4:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/resources.jsp" %>


<html>
<head>
    <title>管理员列表</title>
</head>
<body>
<div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">查询条件</h3>
        </div>
        <div class="panel-body">
            <form class="form-inline">
                <div class="form-group">
                    <label for="searchName">名称：</label>
                    <input type="text" class="form-control" id="searchName" name="name" placeholder="名称">
                </div>
                <div class="form-group">
                    <label for="searchKey">参数：</label>
                    <input type="text" class="form-control" id="searchKey" name="pkey" placeholder="参数">
                </div>
                <button type="button" class="btn btn-info btn-search">查询</button>
                <button type="button" class="btn btn-default btn-reset">清空</button>
            </form>
        </div>
    </div>
</div>

<div class="ems_table_content">
    <div class="panel panel-default">
        <div class="panel-heading">管理员列表</div>
        <div id="table_tools">
            <div class="form-inline" role="form">
                <button type="button" id="system_param_add" class="btn btn-outline btn-success">
                    <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
                    添加
                </button>
                <button type="button" id="system_param_edit" class="btn btn-outline btn-primary">
                    <i class="glyphicon glyphicon-edit" aria-hidden="true"></i>
                    修改
                </button>
                <%--<button type="button" id="system_param_delete" class="btn btn-outline btn-danger">--%>
                    <%--<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>--%>
                    <%--删除--%>
                <%--</button>--%>
            </div>
        </div>
        <table id="systemParamTable"
               data-url="/ems/param/pagination"
               data-show-export="true">
            <thead>
            <tr>
                <th data-field="state" data-checkbox="true"></th>
                <th data-field="name">名称</th>
                <th data-field="pkey">参数</th>
                <th data-field="pvalue">参数值</th>
                <th data-field="to_client" data-formatter="toClientFormat">是否下发客户端</th>
                <th data-field="status" data-formatter="statusFormat">状态</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<script>
    function statusFormat(srcValue) {

        if (srcValue == 1) {
            return "<span style='color: #3cb371;font-weight: bold' >正常</span>";
        }else {
            return "<span style='color: red;font-weight: bold'>冻结</span>";
        }
    }

    function toClientFormat(srcValue) {
        if (srcValue == 1) {
            return "<span style='color: #3cb371;font-weight: bold' >是</span>";
        }else {
            return "<span style='color: red;font-weight: bold'>否</span>";
        }
    }

</script>

<script>

    var dialogOption = {
        width:"500px",
        height:"450px",
        url:"/ems/param/edit",
        yesFn:function(){
            var result = systemParamSave();
            if (result) search("#systemParamTable",getQueryParams());
            return result;
        }
    }

    $(function () {
        $("#systemParamTable").createTable();

        //添加
        $("#system_param_add").on("click",function () {
            dialogOption.data = {};
            dialogOption.title = "参数新增";
            $("#system_param_add_dialog").openDialog(dialogOption);
        })

        //编辑
        $("#system_param_edit").on("click",function () {
            var selectRows =  $('#systemParamTable').bootstrapTable('getSelections');
            if (selectRows.length == 0) {
                $.errorAlert("请选择要编辑的数据");
                return;
            }
            if (selectRows.length > 1) {
                $.errorAlert("暂时不支持多行数据编辑");
                return;
            }

            var rowId =  selectRows[0].id;
            dialogOption.title = "参数编辑";
            dialogOption.data = {systemParamId : rowId};
            $("#system_param_add_dialog").openDialog(dialogOption);
        })

        //删除
        $("#system_param_delete").on("click",function () {
            var selectRows =  $('#systemParamTable').bootstrapTable('getSelections');
            if (selectRows.length == 0) {
                $.errorAlert("请选择要删除的数据");
                return;
            }

            var systemParamIdList = "";
            for (var i = 0;i<selectRows.length;i++) {
                systemParamIdList += selectRows[i].id + ",";
            }
            systemParamIdList = systemParamIdList.substring(0,systemParamIdList.length - 1);

            $.confirmAlert("你确定要删除这些数据吗",function(){
                $.emsAjax({
                    data:{systemParamIdList:systemParamIdList},
                    type:"POST",
                    url:"/ems/param/delete",
                    success:function(resp) {
                        if (resp.status == "000") {
                            $.alert(resp.message);
                            search("#systemParamTable",getQueryParams());
                        }else {
                            $.errorAlert(resp.message);
                        }
                    }
                });
            });
        });
    })
</script>
<div id="system_param_add_dialog"></div>
</body>
</html>
